/* Copyright (C) 2008 Sahid Ferdjaoui <sahid@funraill.org>
 *
 *   This file is part of Postmemd.
 *
 * Postmemd is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef PM_HEAD_H
#define PM_HEAD_H

/**
 * @file pm_head.h
 * @brief Postmem definitions
 */

#define PM_MSG_CMD_SIZE 10;
#define PM_MSG_KEY_SIZE 41;


/**
 * Message Flags
 */
#define PM_MSG_COMMAND     "command"
#define PM_MSG_DATA        "data"
#define PM_MSG_DATA_KEY    "key"
#define PM_MSG_DATA_SIZE   "size"
#define PM_MSG_DATA_EXPIRE "expire"

#define PM_STR_CMD_ADD "add"
#define PM_STR_CMD_SET "set"
#define PM_STR_CMD_GET "get"
#define PM_STR_CMD_DEL "del"

/**
 * Command Bits
 */
#define PM_CMD_ADD 0x01
#define PM_CMD_SET 0x02
#define PM_CMD_DEL 0x03
#define PM_CMD_GET 0x04

#define PM_RESPONSE_FAILED "FAILED"
#define PM_RESPONSE_SUCCESS "SUCCESS"

/**
 * Server states
 */
typedef enum _state {
	pm_close,         /** close connection */

	pm_read_client,   /** read file descriptor */
	pm_read_slave,
	pm_read_master,

	pm_write_client,
	pm_write_slave,         /** write into the file descriptor */
	pm_write_master,


	pm_parse_json,

	pm_dispatch


} state_t;


typedef struct response {
	char commande[4];
	char key[41];
	char status[10];
	int data_bytes;
	char * data;
} response_t;

#endif
